package com.zhimeng.personal.models;

import android.util.Log;

import com.google.gson.Gson;
import com.zhimeng.personal.utils.ApiUtils;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sunzhimeng on 16/4/5.
 */
public class Workinfo extends Record {
    private String company, address, come_time, leave_time, boss, boss_phone, wage_abs, image_urls, duration, description, avg_wage_s, total_wage_s;

    public boolean isLaopo() {
        return laopo;
    }

    public void setLaopo(boolean laopo) {
        this.laopo = laopo;
    }

    private boolean laopo;

    private List<Partner> partners;
    private List<Interview> interviews;

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCome_time() {
        return come_time;
    }

    public void setCome_time(String come_time) {
        this.come_time = come_time;
    }

    public String getLeave_time() {
        return leave_time;
    }

    public void setLeave_time(String leave_time) {
        this.leave_time = leave_time;
    }

    public String getBoss() {
        return boss;
    }

    public void setBoss(String boss) {
        this.boss = boss;
    }

    public String getBoss_phone() {
        return boss_phone;
    }

    public void setBoss_phone(String boss_phone) {
        this.boss_phone = boss_phone;
    }

    public String getWage_abs() {
        return wage_abs;
    }

    public void setWage_abs(String wage_abs) {
        this.wage_abs = wage_abs;
    }

    public String getImage_urls() {
        return image_urls;
    }

    public void setImage_urls(String image_urls) {
        this.image_urls = image_urls;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration = duration;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getAvg_wage_s() {
        return avg_wage_s;
    }

    public void setAvg_wage_s(String avg_wage_s) {
        this.avg_wage_s = avg_wage_s;
    }

    public String getTotal_wage_s() {
        return total_wage_s;
    }

    public void setTotal_wage_s(String total_wage_s) {
        this.total_wage_s = total_wage_s;
    }

    public List<Partner> getPartners() {
        return partners;
    }

    public void setPartners(List<Partner> partners) {
        this.partners = partners;
    }

    public List<Interview> getInterviews() {
        return interviews;
    }

    public void setInterviews(List<Interview> interviews) {
        this.interviews = interviews;
    }


    public String getHeadImage(){
        String image = getImage_urls().split(",")[0];
        return image.equals("") ? "" : ApiUtils.HOST + image;
    }

    public String getPeriod(){
        String endTime;
        if (getLeave_time().equals(""))
            endTime = "Now";
        else
            endTime = getLeave_time();
        return getCome_time() + " / " + endTime;
    }

    private Workinfo parseWorkinfoFromData(JSONObject workinfoJSON){
        String s = workinfoJSON.toString();
        Gson gson = new Gson();
        Workinfo w = gson.fromJson(s, Workinfo.class);
        return w;
    }

    public static List<Workinfo> parseWorkinfosFromData(JSONObject data){
        List<Workinfo> ws = new ArrayList<>();
        try {
            JSONArray wsArray = data.getJSONArray("workinfos");
            JSONObject workinfoJSON;
            for (int i = 0;i < wsArray.length();i ++){
                workinfoJSON = (JSONObject)wsArray.opt(i);
                Workinfo w = new Workinfo();
                w = w.parseWorkinfoFromData(workinfoJSON);
                ws.add(w);
            }
        } catch (Exception e){
            e.printStackTrace();
        }
        return ws;
    }
}
